/*
 * @Author: Jiraiya
 * @Date: 2020-03-02 18:52:18
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-03-02 20:33:19
 * @Description: 
 */
//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

// 枚举

// 获取对象属性的描述对象
const obj = {
    get foo(){},
    set foo(x){}
}
console.log(Object.getOwnPropertyDescriptor(obj, 'foo'))
/**
 * 
 * { get: [Function: get foo],
 *   set: [Function: set foo],
 *   enumerable: true,
 *   configurable: true }
 */

 const cc = Symbol('a')
 const b = Symbol('b')
 const father = {aa:1, bb:2}
 father[cc] = 3
 const son = Object.create(father, {a: {
     enumerable: true,
     writable: true,
     configurable: true,
     value: 11
 }})
son[b] = 22

console.log(son, son.__proto__)

 // 返回自身和继承的可枚举属性(不包括symbol)
 for(let val in son){
     console.log(val)
 }
 // c aa bb

 
 //自身可枚举属性(不包括symbol)组成的数组
 console.log(Object.keys(son)) // ['a']
 
 // 自身可枚举属性(包括symbol)
 console.log(Object.assign({}, son))

 //自身可枚举和不可枚举属性（不包括symbol）
 console.log(Object.getOwnPropertyNames(son))

//自身所有的symbol属性
console.log(Object.getOwnPropertySymbols(son))

//自身所有属性包括不可枚举和symbol
console.log(Reflect.ownKeys(son))

// super
const proto = {
    foo: 'hello'
}
const obj = {
    find(){
        return super.foo;
    },
    compare(){
        return super.foo === Object.getPrototypeOf(this).foo
    }
}
Object.setPrototypeOf(obj, proto)
console.log(obj.find()) // hello

console.log(obj.compare()) // true

// 链判断运算符
const firstName = (
    message
    && message.body
    && message.body.user
    && message.body.user.firstName
) || default

const firstName = message?.body?.user?.firstName || default

console.log(null || undefined || 1)
console.log(null ?? undefined ?? 1)

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

// 判断相等 规避了NaN 和 -0 +0
console.log(Object.is(0, +0)) // true
console.log(Object.is(0, -0)) // false

// 浅合并对象
console.log(Object.assign({}, {a: 1}))

// 为类的实例添加属性
class Point{
    constructor(x, y){
        Object.assign(this, x, pageYOffset)
    }
}


//对象的fromEntries
const obj = {a: 1}
console.log(Object.fromEntries(Object.entries(obj)) === obj) // true